package com.sam.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @project mould
 * @author Sam
 * @version
 * @date Nov 11, 2009 4:47:23 PM
 */
public class DateUtils {
	private static SimpleDateFormat format = new SimpleDateFormat();

	public static void main(String[] args) {
		System.out.println(formatYMD(new Date()));
	}

	public static String formatYMD(Date date) {
		if (date != null) {
			format.applyPattern("yyyy-MM-dd");
			return format.format(date);
		} else {
			return "";
		}
	}

	public static Date max(Date date1, Date date2) {
		if (date1 == null) {
			return date2;
		}
		if (date2 == null) {
			return date1;
		}
		if (date1.compareTo(date2) >= 0) {
			return date1;
		} else {
			return date2;
		}
	}

	public static String getDefinateTime(String ts, boolean isQueryBegin) {
		String date = null;
		if (isQueryBegin) {
			if (StringUtils.isEmpty(ts)) {
				date = "1970-01-01 00:00:01";
			} else {
				date = ts.substring(0, 10) + " 00:00:01";
			}
		} else {
			if (StringUtils.isEmpty(ts)) {
				date = "2500-12-31 23:59:59";
			} else {
				date = ts.substring(0, 10) + " 23:59:59";
			}
		}
		return date;
	}

}
